
#include "Config.h"
#include "reg.h"
#include "typedefs.h"
#include "CPU.h"
#include "util.h"
#include "Printf.h"
#include "I2C.h"
#include "Global.h"
#include "OSD\dv_OSD.h"
#include "OSD\app_OSD.h"
#include "OSD\User_handle.h"
#include "app_GUI.h"
#include "app_SRC.h"

extern void ShowCanvasByPageid(U8 page_id);

U8 CurHidePageID = 0xFF;
 
void TaskGUI(void)
{
	static U8 clicktime=0;
	msg_data_t msg;
	LPUIPAGE  lpPage;

	
	if (GetMessage(&msg) != 0)
	{
		return;
	}

	//Printf("\r\n TaskGUI x|y %d|%d", msg.mparal, msg.mparan);
	//OSD_BlockFill(msg.mparal, msg.mparan+480, 2, 2, 0xF800, 16);
/*	
	if (((msg.mtype == CMD_TOUCH)&&(msg.mparam == KWUI_TOUCH_DOWN))||((msg.mtype == CMD_TOUCH)&&(msg.mparam == KWUI_TOUCH_UP)))
	{
		if (msg.mparal>100)
		{
			if (clicktime == 2)
			{
				clicktime = 0;
			}
			if ((CurHidePageID >= 0)&&(CurHidePageID <= 10))
			{
				clicktime++;
			}
		}
	}
	
	if (((msg.mtype == CMD_KEY)&&(msg.mparam == KWUI_KEYPAD_SEL))|| ((msg.mtype == CMD_IR)&&(msg.mparam == KWUI_IR_SEL)))
	{
		ZCreatePage(10);
		CurHidePageID = 0xFF;
		clicktime = 0;
	}
	
	if ((CurHidePageID >= 0)&&(CurHidePageID <= 11)&&(msg.mparal<100))
	{
		ZCreatePage(10);
		CurHidePageID = 0xFF;
		clicktime = 0;
	}
*/	
/*	
	//Printf("\r\n TaskGUI CurHidePageID %bd clicktime %bd", CurHidePageID, clicktime);
	//Printf("\r\nmsg.mtype=%x,msg.mparal=%x\r\n ",msg.mtype,msg.mparal);
	if((CurHidePageID == PIPMODEPAGE_IDX)&&(clicktime == 2)){
		Change_PIPMode(PIP_OFF);
		Update_Mode();
		ShowCanvasByPageid(CurHidePageID);
		//lpPage = GetPageHandle(CurHidePageID);
		//TWLL_WaitDisplayBlank(1);
		//TWLL_Canvas_OnOff(lpPage->nWinno, 1);
		CurHidePageID = 0xFF;
		clicktime = 0;
	}else if((CurHidePageID == PIPSETTINGPAGE_IDX)&&(clicktime == 2)){
		//lpPage = GetPageHandle(CurHidePageID);
		//TWLL_Canvas_OnOff(lpPage->nWinno, 1);
		ShowCanvasByPageid(CurHidePageID);
		CurHidePageID = 0xFF;
		clicktime = 0;
	}else if((CurHidePageID >= HOMEPAGE_IDX)&&(CurHidePageID <= PIGEONPAGE_IDX)&&(clicktime == 2)){
    	ZCreatePage(0);
		CurHidePageID = 0xFF;
		clicktime = 0;
	}else if(CurHidePageID == 0xff)
*/	
	{
		ProcessMessage(msg.mtype, msg.mitem, msg.mparam, msg.mparal, msg.mparan);
	}
}

//eamon.fang
void osd_animation(U16 index, U16 length)
{
	U16 i;
	U8 j;
	
	TWLL_OSDLayer_Init();	
	TWLL_Canvas_Init(&User_Canvas[3]);
	
	OSD_BlockFill(0, 480, 480, 272, 0, 16);			// color 0 is transparent

	WriteTW88(0xff, OSD_PAGE);
	WriteTW88(0xc0, 0x33);
	WriteTW88(0xDC, 0);
	WriteTW88(0xD6, 0x0f);
	WriteTW88(0xD7, 0xff);
	WriteTW88(0xDD, 0x7f);

	OSD_ShowWindowBmp(0, 0);
	OSD_ShowWindowBmp(1, 0);
	OSD_ShowWindowBmp(2, 1);
	
	for (i = 0; i<length; i++)
	{
		TWLL_WaitDisplayBlank(1);
		OSD_LoadBmp((const U8 *)&SystemIcon[i+index], 0, 480, 16);
		for (j=0; j<100; j++)
			;
	}
}

void Init_GUIAPP(void)
{
	TWLL_OSDLayer_Init();
	
    InitCoreTimer(20);
	ZInit_App(HOMEPAGE_IDX);
 	CurHidePageID = 0;

	return;
}

extern CHARACTERINFO Unicode_Font_char_info[];  //use for unicode font
static WORD x = 100;
static WORD y = 100;
void Monit_GUIUnicode(void)
{
	WORD unicode;
	WORD i;

	unicode = 0;
	i = 0;
	//Printf("\nUnicodetest\r\n");
	//Printf("\r\ncode 0x%x",unicode);
	for(i=1;i<argc;i++){
		unicode = (WORD)(a2h(argv[i]));
		//Printf("\r\ncode 0x%x",unicode);
	    ZPrintf_Unicode(x, y, 0x0,0x7ff, 2, unicode);
		x += Unicode_Font_char_info[0].character_width;
		if(x>700){
			x = 100;
			y += 30;
		}
	}

	return;
}



 
